// pages/index1/index1.js
Page({
  data: {
    index_img_list: [],
    //0-审核中，1-通过，2-拒绝  //-2未登录  -1未提交
    status: -2,
    id: ""
  },
  onLoad(options) {
    this.getConfigNet();
    this.onPullDownRefresh();
  },
  onPullDownRefresh(){
    var token = wx.getStorageSync('token');
    console.log(token);
    if (token) {
      this.getNet();
    } else {
      wx.stopPullDownRefresh();
      this.setData({
        status: -2
      })
    }
  },
  getConfigNet() {
    var that = this;
    var index_img_list = wx.getStorageSync('index_img_list');
    var index1_share = wx.getStorageSync('index1_share');
    that.setData({
      "index_img_list": index_img_list,
      "index1_share": index1_share
    })
    wx.request({
      url: 'https://api.dianshiyexiao.com/weapp/config',
      method: 'POST',
      success(res) {
        console.log(res.data.data)
        var index_img_list = [];
        var detail_img_list = [];
        var index1_share = "";
        var index2_share = "";
        res.data.data.forEach(element => {
          console.log(element)
          if (element.type == "index_img") {
            index_img_list.push(element.value)
          }
          if (element.type == "detail_img") {
            detail_img_list.push(element.value)
          }
          if (element.type == "index1_share") {
            index1_share = element.value;
          }
          if (element.type == "index2_share") {
            index2_share = element.value;
          }
        });
        wx.setStorageSync("index_img_list", index_img_list)
        wx.setStorageSync("detail_img_list", detail_img_list)
        wx.setStorageSync("index1_share", index1_share)
        wx.setStorageSync("index2_share", index2_share)
        that.setData({
          "index_img_list": index_img_list,
          "index1_share": index1_share
        })
      },
      fail(error) {
        console.log(error)
      },
    })
  },
  onShow() {

  },
  getNet() {
    var that = this;
    wx.request({
      url: 'https://api.dianshiyexiao.com/weapp/company/info',
      method: 'POST',
      header: {
        'Authorization': wx.getStorageSync('token') // 默认值
      },
      success(res) {
        wx.stopPullDownRefresh();
        console.log(res.data)
        if (res.data.data.info) {
          that.setData({
            status: res.data.data.info.status,
            id: res.data.data.info.id
          })
          //wx.setStorage("net",res.data.data.info)
        } else {
          that.setData({
            status: -1
          })
        }
      },
      fail(error) {
        wx.stopPullDownRefresh();
        console.log(error)
      },
    })
  },

  baoming() {
    var token = wx.getStorageSync('token');
    if (token) {
      wx.navigateTo({
        url: '/pages/upload/upload?upload_status=0',
      })
    } else {
      wx.navigateTo({
        url: '/pages/login/login',
      })
    }
  },
  chakan() {
    var that = this;
    if (that.data.status == 0) { //审核中
      wx.navigateTo({
        url: '/pages/yulan/yulan?yulan_status=1',
      })
    } else if (that.data.status == 2) { //审核失败
      wx.navigateTo({
        url: '/pages/upload/upload?upload_status=1',
      })
    } else if (that.data.status == 1) { //审核成功
      wx.navigateTo({
        url: '/pages/votedetail/votedetail?id=' + that.data.id,
      })
    }

  },
  onShareAppMessage() {
    return {
      title: ("雨林好物,开始报名啦!"),
      path: '/pages/index1/index1',
      imageUrl: this.data.index1_share
    }
  },
  onShareTimeline() {
    return {
      title: ("雨林好物,开始报名啦!"),
      path: '/pages/index1/index1',
    }
  }
})